package com.bsj.power.common.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bsj.power.common.def.entity.gb28181.DeviceChannel;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description 用于存储设备通道信息
 * @Author zhaoyang
 * @Date 2024/4/23 14:33
 */
@Mapper
@Repository
public interface DeviceChannelMapper extends BaseMapper<DeviceChannel> {

    List<DeviceChannel> queryAllChannels(String deviceId);

    //
//    @Update(value = {"UPDATE tab_device_channel SET stream_id=null WHERE device_id=#{deviceId} AND channel_id=#{channelId}"})
//    void stopPlay(String deviceId, String channelId);
//
//    @Select("SELECT * FROM tab_device_channel WHERE device_id=#{deviceId} AND channel_id=#{channelId}")
//    DeviceChannel queryChannel(String deviceId, String channelId);
//
//    @Update(value = {"UPDATE tab_device_channel SET stream_id=#{streamId} WHERE device_id=#{deviceId} AND channel_id=#{channelId}"})
//    void startPlay(@Param("deviceId") String deviceId, @Param("channelId") String channelId, @Param("streamId") String streamId);
//
//
//    @Select(value = {" <script>" +
//            "SELECT " +
//            "dc.id, " +
//            "dc.channel_id, " +
//            "COALESCE(dc.custom_name, dc.name) AS name, " +
//            "dc.manufacture, " +
//            "dc.model, " +
//            "dc.owner, " +
//            "dc.civil_code, " +
//            "dc.block, " +
//            "dc.address, " +
//            "dc.parent_id, " +
//            "dc.safety_way, " +
//            "dc.register_way, " +
//            "dc.cert_num, " +
//            "dc.certifiable, " +
//            "dc.err_code, " +
//            "dc.end_time, " +
//            "dc.secrecy, " +
//            "dc.ip_address, " +
//            "dc.port, " +
//            "dc.password, " +
//            "COALESCE(dc.custom_ptz_type, dc.ptz_type) AS ptz_type, " +
//            "dc.status, " +
//            "COALESCE(dc.custom_longitude, dc.longitude) AS longitude, " +
//            "COALESCE(dc.custom_latitude, dc.latitude) AS latitude, " +
//            "dc.stream_id, " +
//            "dc.device_id, " +
//            "dc.parental, " +
//            "dc.has_audio, " +
//            "dc.create_time, " +
//            "dc.update_time, " +
//            "dc.sub_count, " +
//            "dc.longitude_gcj02, " +
//            "dc.latitude_gcj02, " +
//            "dc.longitude_wgs84, " +
//            "dc.latitude_wgs84, " +
//            "dc.business_group_id, " +
//            "dc.stream_identification, " +
//            "dc.gps_time " +
//            "from " +
//            "tab_device_channel dc " +
//            "WHERE " +
//            "dc.device_id = #{deviceId} " +
//            " <if test='query != null'> AND (" +
//            "dc.channel_id LIKE concat('%',#{query},'%') " +
//            "OR dc.name LIKE concat('%',#{query},'%') " +
//            "OR dc.custom_name LIKE concat('%',#{query},'%')" +
//            ")</if> " +
//            " <if test='parentChannelId != null'> AND (dc.parent_id=#{parentChannelId} OR dc.civil_code = #{parentChannelId}) </if> " +
//            " <if test='online == true' > AND dc.status= true</if>" +
//            " <if test='online == false' > AND dc.status= false</if>" +
//            " <if test='hasSubChannel == true' >  AND dc.sub_count > 0 </if>" +
//            " <if test='hasSubChannel == false' >  AND dc.sub_count = 0 </if>" +
//            "<if test='channelIds != null'> AND dc.channel_id in <foreach item='item' index='index' collection='channelIds' open='(' separator=',' close=')'>" +
//            "#{item} " +
//            "</foreach> </if>" +
//            "ORDER BY dc.channel_id " +
//            " </script>"})
//    List<DeviceChannel> queryChannels(@Param("deviceId") String deviceId, @Param("parentChannelId") String parentChannelId, @Param("query") String query, @Param("hasSubChannel") Boolean hasSubChannel, @Param("online") Boolean online, @Param("channelIds") List<String> channelIds);
//
//
//    int cleanChannelsByDeviceId(@Param("deviceId") String deviceId);
//
//
//    @Update(value = {" <script>" +
//            "UPDATE tab_device_channel " +
//            "SET " +
//            "latitude=#{latitude}, " +
//            "longitude=#{longitude}, " +
//            "longitude_gcj02=#{longitudeGcj02}, " +
//            "latitude_gcj02=#{latitudeGcj02}, " +
//            "longitude_wgs84=#{longitudeWgs84}, " +
//            "latitude_wgs84=#{latitudeWgs84}, " +
//            "gps_time=#{gpsTime} " +
//            "WHERE device_id=#{deviceId} " +
//            " <if test='channelId != null' >  AND channel_id=#{channelId}</if>" +
//            " </script>"})
//    int updatePosition(DeviceChannel deviceChannel);
//
//
//    List<DeviceChannel> queryChannelWithCatalog(String serverGBId);
//
//
    int batchAdd(@Param("addChannels") List<DeviceChannel> subList);
//
//
//    int batchUpdate(List<DeviceChannel> subList);
//
//
//    int batchDel(@Param("deleteChannelList") List<DeviceChannel> deleteChannelList);
//
//    List<DeviceChannel> queryChannelByChannelId(String channelId);

    int deleteByDeviceId(String deviceId);

    List<DeviceChannel> queryAllByDeviceIds(@Param("list") List<String> deviceIds);

    int updateChannelDevice(@Param("deviceId") String deviceId, @Param("channelId") String channelId
            , @Param("mediaType") String mediaType, @Param("serialNum") Integer serialNum);


    DeviceChannel queryChannelByDeviceIdAndSerial(@Param("deviceId") String deviceId, @Param("channelSerial") Integer channelSerial);

    DeviceChannel selectByDeviceIdAndChannelId(@Param("deviceId") String deviceId, @Param("channelId") String channelId);

    DeviceChannel selectByDeviceIdAndChannelIdAndSerialNum(@Param("deviceId") String deviceId
            , @Param("channelId") String channelId, @Param("serialNum") Integer serialNum);
}
